package com.yunshan.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yunshan.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yunshan.common.annotation.Log;
import com.yunshan.common.core.controller.BaseController;
import com.yunshan.common.core.domain.AjaxResult;
import com.yunshan.common.enums.BusinessType;
import com.yunshan.order.domain.OrderConsumeRecord;
import com.yunshan.order.service.IOrderConsumeRecordService;
import com.yunshan.common.utils.poi.ExcelUtil;
import com.yunshan.common.core.page.TableDataInfo;

/**
 * 消费订单Controller
 * 
 * @author yunshan
 * @date 2025-01-20
 */
@Api(tags = "消费订单")
@RestController
@RequestMapping("/order/consume")
public class OrderConsumeRecordController extends BaseController
{
    @Autowired
    private IOrderConsumeRecordService orderConsumeRecordService;

    /**
     * 查询消费订单列表
     */
    @ApiOperation("查询消费订单列表")
    @PreAuthorize("@ss.hasPermi('order:consume:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderConsumeRecord orderConsumeRecord)
    {
        startPage();
        List<OrderConsumeRecord> list = orderConsumeRecordService.selectOrderConsumeRecordList(orderConsumeRecord);
        return getDataTable(list);
    }

    /**
     * 导出消费订单列表
     */
    @ApiOperation("导出消费订单列表")
    @PreAuthorize("@ss.hasPermi('order:consume:export')")
    @Log(title = "消费订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderConsumeRecord orderConsumeRecord)
    {
        List<OrderConsumeRecord> list = orderConsumeRecordService.selectOrderConsumeRecordList(orderConsumeRecord);
        ExcelUtil<OrderConsumeRecord> util = new ExcelUtil<OrderConsumeRecord>(OrderConsumeRecord.class);
        util.exportExcel(response, list, "消费订单数据");
    }

    /**
     * 获取消费订单详细信息
     */
    @ApiOperation("获取消费订单详细信息")
    @PreAuthorize("@ss.hasPermi('order:consume:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderConsumeRecordService.selectOrderConsumeRecordById(id));
    }

    /**
     * 新增消费订单
     */
    @ApiOperation("新增消费订单")
    @PreAuthorize("@ss.hasPermi('order:consume:add')")
    @Log(title = "消费订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderConsumeRecord orderConsumeRecord)
    {
        if (StringUtils.isEmpty(orderConsumeRecord.getPhone())){
            return AjaxResult.error("请填写完整信息");
        }
        return toAjax(orderConsumeRecordService.insertOrderConsumeRecord(orderConsumeRecord));
    }

    /**
     * 修改消费订单
     */
    @ApiOperation("修改消费订单")
    @PreAuthorize("@ss.hasPermi('order:consume:edit')")
    @Log(title = "消费订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderConsumeRecord orderConsumeRecord)
    {
        return toAjax(orderConsumeRecordService.updateOrderConsumeRecord(orderConsumeRecord));
    }

    /**
     * 删除消费订单
     */
    @ApiOperation("删除消费订单")
    @PreAuthorize("@ss.hasPermi('order:consume:remove')")
    @Log(title = "消费订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderConsumeRecordService.deleteOrderConsumeRecordByIds(ids));
    }
}
